package a51qindian.com.comprehensive.activity;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.li.widget.TopNavigationBar;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import a51qindian.com.comprehensive.Const;
import a51qindian.com.comprehensive.R;
import a51qindian.com.comprehensive.base.QDBaseActivity;
import a51qindian.com.comprehensive.fragment.TaskInstallFragment;
import a51qindian.com.comprehensive.fragment.TaskRepairFragment;
import butterknife.BindView;


/**
 * Author: Li
 * Date: 2017/9/13 0013
 * Description: 任务处理界面
 */

public class TaskProcessingActivity extends QDBaseActivity {

    @BindView(R.id.top_navigation)
    TopNavigationBar mTopNavigation;
    @BindView(R.id.tab_task)
    TabLayout mTabTask;
    @BindView(R.id.pager_task)
    ViewPager mPagerTask;


    private List<String> mTitleList;
    private List<Fragment> mFragmentList;

    public static final String TYPE_FIRST_INSTALL="0";
    public static final String TYPE_ADD_INSTALL="1";
    public static final String TYPE_REPAIR="2";

    @Override
    protected int getLayoutId() {
        return R.layout.activity_task_processing;
    }

    private String mType;
    @Override
    protected void initSth() {
        super.initSth();
        mType=getIntent().getStringExtra("type");
        mTopNavigation.setNavigationBarListener(this);
        mTitleList= Arrays.asList(Const.TASK_UN_ACCEPTED,Const.TASK_COMPLETED);
        mFragmentList=new ArrayList<>();

        switch (mType) {
            case TYPE_FIRST_INSTALL:
                mTopNavigation.setTitle("首装任务");
                mFragmentList.add(
                        TaskInstallFragment.newInstance(TaskInstallFragment.TASK_FIRST_INSTALL,
                                TaskInstallFragment.TASK_UN_ACCEPTED));

                mFragmentList.add(
                        TaskInstallFragment.newInstance(TaskInstallFragment.TASK_FIRST_INSTALL,
                                TaskInstallFragment.TASK_FINISHED));


                break;
            case TYPE_ADD_INSTALL:
                mTopNavigation.setTitle("加装任务");
                mFragmentList.add(
                        TaskInstallFragment.newInstance(TaskInstallFragment.TASK_ADD_INSTALL,
                                TaskInstallFragment.TASK_UN_ACCEPTED));

                mFragmentList.add(
                        TaskInstallFragment.newInstance(TaskInstallFragment.TASK_ADD_INSTALL,
                                TaskInstallFragment.TASK_FINISHED));
                break;
            case TYPE_REPAIR:
                mTopNavigation.setTitle("维修任务");
                mFragmentList.add(TaskRepairFragment.newInstance(TaskRepairFragment.TASK_UN_ACCEPTED));
                mFragmentList.add(TaskRepairFragment.newInstance(TaskRepairFragment.TASK_FINISHED));
                break;
        }




        mPagerTask.setOffscreenPageLimit(mFragmentList.size());
        mPagerTask.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return mFragmentList.get(position);
            }

            @Override
            public int getCount() {
                return mFragmentList.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return mTitleList.get(position);
            }
        });
        mTabTask.setupWithViewPager(mPagerTask);
    }
}
